package com.quan.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.admin.entity.SysDictDetail;
import com.quan.admin.mapper.SysDictDetailMapper;
import com.quan.admin.service.SysDictDetailService;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysDictDetailServiceImpl extends MyBaseServiceImpl<SysDictDetailMapper, SysDictDetail> implements SysDictDetailService {

    @Autowired
	private SysDictDetailMapper mapper;

	@Override
    public IPage<SysDictDetail> selectMyPage(PageUtils pageUtils, SysDictDetail entity) {
        Page<SysDictDetail> page = new Page<SysDictDetail>(pageUtils.getPage(), pageUtils.getLimit());

        // 排序
        super.handleSort(page, pageUtils);

        return this.mapper.selectMyPage(page, entity);
    }

    @Override
    public boolean clearSelected(Long dictId) {

        UpdateWrapper<SysDictDetail> updateWrapper = new UpdateWrapper<SysDictDetail>();
        updateWrapper.set("selected", false).eq("dict_id", dictId) ;

        return super.update(updateWrapper) ;
    }

    @Override
    public boolean deleteByDictId(List<Long> dictIds) {
        QueryWrapper<SysDictDetail> queryWrapper = new QueryWrapper<SysDictDetail>();
        queryWrapper.in("dict_id", dictIds);
        return super.remove(queryWrapper);
    }

}